package Dynamic_programming;

import org.checkerframework.checker.units.qual.A;
import org.junit.Test;

import java.util.*;

/**
 * @Description: $
 * @Param: $
 * @return: $
 * @Author 万家欣
 * @Date: 2022/6/28
 * Algorithm
 * @Version 1.0
 */
public class Demo2 {
    @Test
    public void  t (){
       // System.out.println(numSmallerByFrequency(   new String[]{"bba","abaaaaaa","aaaaaa","bbabbabaab","aba","aa","baab","bbbbbb","aab","bbabbaabb"},new String[]{"aaabbb","aab","babbab","babbbb","b","bbbbbbbbab","a","bbbbbbbbbb","baaabbaab","aa"}));

        System.out.println(containVirus(new int[][]{{0, 1, 0, 0, 0, 0, 0, 1}, {0, 1, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 0}}));
    }
    public int[] numSmallerByFrequency(String[] queries, String[] words) {
        int[] sum = new int[2001];
        Arrays.fill(sum,0);
        for (String x:words) {
            sum[x.length()]++;
        }
        for (int i = 1; i < sum.length; i++) {
            sum[i] = sum[i] + sum[i - 1];
        }
        int[] res = new int[queries.length];
        for (int i = 0; i < queries.length; i++) {
            res[i] = sum[2000] - sum[queries[i].length()];
        }
        return res;
    }

    public List<List<Integer>> minimumAbsDifference(int[] arr) {
        Arrays.sort(arr);
        List<List<Integer>> res = new ArrayList<>();
        int len = Integer.MAX_VALUE;
        for (int i = 1; i < arr.length; i++) {
            int d = arr[i] - arr[i - 1];
            if(d < len){
                res.clear();
                List<Integer> list = Arrays.asList(arr[i - 1],arr[i]);
                res.add(list);
                len = d;
            }else  if(d == len){
                List<Integer> list = Arrays.asList(arr[i - 1],arr[i]);
                res.add(list);
            }
        }
        return res;
    }
    int[][] g;
    int n, m, ans;
    int[][] dirs = new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
    boolean[][] vis;
    int search(int _x, int _y, Set<Integer> s1, Set<Integer> s2) {
        int ans = 0;
        Deque<int[]> d = new ArrayDeque<>();
        vis[_x][_y] = true;
        d.addLast(new int[]{_x, _y});
        s1.add(_x * m + _y);
        while (!d.isEmpty()) {
            int[] info = d.pollFirst();
            int x = info[0], y = info[1];
            for (int[] di : dirs) {
                int nx = x + di[0], ny = y + di[1], loc = nx * m + ny;
                if (nx < 0 || nx >= n || ny < 0 || ny >= m || vis[nx][ny]) continue;
                if (g[nx][ny] == 1) {
                    s1.add(loc);
                    vis[nx][ny] = true;
                    d.addLast(new int[]{nx, ny});
                } else if (g[nx][ny] == 0) {
                    s2.add(loc);
                    ans++;
                }
            }
        }
        return ans;
    }
    int getCnt() {
        vis = new boolean[n][m];
        int max = 0, ans = 0;
        // l1: 每个连通块的点集 s2: 每个连通块的候选感染点集
        List<Set<Integer>> l1 = new ArrayList<>(), l2 = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (g[i][j] == 1 && !vis[i][j]) {
                    // s1: 当前连通块的点集 s2: 当前连通块的候选感染点集
                    Set<Integer> s1 = new HashSet<>(), s2 = new HashSet<>();
                    int b = search(i, j, s1, s2), a = s2.size();
                    if (a > max) {
                        max = a; ans = b;
                    }
                    l1.add(s1); l2.add(s2);
                }
            }
        }
        for (int i = 0; i < l2.size(); i++) {
            for (int loc : l2.get(i).size() == max ? l1.get(i) : l2.get(i)) {
                int x = loc / m, y = loc % m;
                g[x][y] = l2.get(i).size() == max ? -1 : 1;
            }
        }
        return ans;
    }
    public int containVirus(int[][] _g) {
        g = _g;
        n = g.length; m = g[0].length;
        while (true) {
            int cnt = getCnt();
            if (cnt == 0) break;
            ans += cnt;
        }
        return ans;
    }
@Test
    public void  tt(){
    /*Skiplist skiplist = new Skiplist();
    skiplist.add(5);
    skiplist.add(9);
    skiplist.add(8);
    skiplist.search(5);
    skiplist.erase(5);*/
    double d = 0.999;
  //  System.out.println((fractionAddition("-10/3-5/3-1/4-5/1+7/10")));
    String x ="R_W_1/59";
    String[] flag = "V_W_1/59".split("_");
    if(!(flag == null || !x.contains("V") || "R".equals(flag[1]))){
        System.out.println("sadas");
    }
}
    public String fractionAddition(String expression) {
        //将每一个数拆分为【分子，分母】，将所有的分母同分后分子进行加减后和分母进行简化：
        char c = ' ';
        char d = ' ';
        int[] a = new int[2];
        int[] b = new int[2];
        int index = 0;
        for (int i = 0; i < expression.length(); i++) {
            if(expression.charAt(i) == '/'){
                if(a[0] == 0 && index == 0){
                    a[0] = Integer.parseInt(expression.substring(index,i));
                }else {
                    b[0] = Integer.parseInt(expression.substring(index,i));
                }
                index = i + 1;
            }else if(i!= 0 &&(expression.charAt(i) == '+' || expression.charAt(i) == '-')){
                if(a[1] == 0) {
                    a[1] = Integer.parseInt(expression.substring(index, i));
                }else {
                    b[1] = Integer.parseInt(expression.substring(index, i));
                }
                c = d;
                d=  expression.charAt(i);
                index = i;
            }

            if(i == expression.length() - 1){
                if(a[1] == 0) {
                    a[1] = Integer.parseInt(expression.substring(index));
                }else {
                    b[1] = Integer.parseInt(expression.substring(index));
                }
                c = d;
                d=  expression.charAt(i);
                index = i;
            }
            if(a[1] != 0 && b[1] != 0){//通分计算：
               int  x = a[1] * b[1];
                a[0] = a[0] * b[1];
                b[0] = b[0] * a[1];
                a[1] = x;
                    a[0 ] = a[0] + b[0];

                //计算完成后将b数组清空：
                b[0] = b[1] = 0;
                if(a[0 ] == 0){
                    a[1] = 1;
                }
            }
        }
        int x = a[0];
        int i = 0;
        if(x != 0){
            if(a[0] < 0){
                a[0] = -a[0];
            }
            for( i=a[0];;i--) {
                if(a[0]%i==0&&a[1]%i==0) {
                    break;
                }
            }
            return (x/i)+"/" + (a[1] / i);
        }else {
            return "0/1";
        }
    }
    long len = -1;
    public boolean validSquare(int[] a, int[] b, int[] c, int[] d) {
        return calc(a, b, c) && calc(a, b, d) && calc(a, c, d) && calc(b, c, d);//判断任意三个点是否能够构成直角三角形并判断每一条边是否相等
    }
    boolean calc(int[] a, int[] b, int[] c) {
        long l1 = (long) (a[0] - b[0]) * (a[0] - b[0]) + (long) (a[1] - b[1]) * (a[1] - b[1]);
        long l2 = (long) (a[0] - c[0]) * (a[0] - c[0]) + (long) (a[1] - c[1]) * (a[1] - c[1]);
        long l3 = (long) (b[0] - c[0]) * (b[0] - c[0]) + (long) (b[1] - c[1]) * (b[1] - c[1]);
        boolean ok = (l1 == l2 && l1 + l2 == l3) || (l1 == l3 && l1 + l3 == l2) || (l2 == l3 && l2 + l3 == l1);
        if (!ok) return false;
        if (len == -1) len = Math.min(l1, l2);
        else if (len == 0 || len != Math.min(l1, l2)) return false;
        return true;
    }
    public String generateTheString(int n) {
        StringBuilder stringBuilder =new StringBuilder();
        char a = 'a';
        char b = 'b';
        if(n % 2 == 0){
            int mid = n - 1;
            while (mid  > 0){
                stringBuilder.append(a);
                mid --;
            }
            stringBuilder.append(b);
        }else {
            while (n  > 0){
                stringBuilder.append(a);n --;
            }
        }
        return stringBuilder.toString();
    }
    public int[] searchRange(int[] nums, int target) {
    int l = findl(nums,target);
    int r = findr(nums,target);
    return new int[]{l,r};
    }
@Test
public void  po(){
        searchRange(new int[]{5, 7, 7, 8, 8, 10},
                6);
}

    private int findr(int[] nums, int target) {
        int l = 0; int r = nums.length - 1;
        while (l < r){
            int mid = l+(r - l)/2;
            if(nums[mid] <= target){
                l = mid + 1;
            }else if(nums[mid] > target){
                r = mid ;
            }
        }
        return l - 1;

    }

    private int findl(int[] nums, int target) {
        int l = 0; int r = nums.length - 1;
        int  res = -1;
        while (l < r){
            int mid = l+(r - l)/2;

            if(nums[mid] >= target){
                r = mid  - 1;  res = mid;
            }else {
                l  = mid + 1;
            }
        }
        return res;
    }
    public int search(int[] nums, int target) {
        int l = 0;
        int r = nums.length;
        while (l < r){
            int mid = l + (r - l)/2;
            if(nums[mid] < target){
                if(nums[l] < target){
                    r = mid ;
                }else if(nums[r] > target) {
                    l = mid ;
                }else {
                    r--;l++;
                }
            }else if(nums[mid] > target){
                if(nums[l] > target){
                    l = mid ;
                }else if(nums[r] < target) {
                    r = mid ;
                }else {
                    r--;l ++;
                }
            }else {
                return mid;
            }
        }
        return  - 1;

    }

    public List<Integer> minSubsequence(int[] nums) {
        //找到和：
     int max =   Arrays.stream(nums).sum();
     Arrays.sort(nums);
     List<Integer> res = new ArrayList<>();
     int sum = 0;
        for (int i = nums.length - 1; i >=0 ; i++) {
            res.add(nums[i]);
            sum += nums[i];
            if(sum >(max - sum)){
                return res;
            }
        }
        return res;

    }
    public int maxProfit(int[] prices) {
        int max =0; int min = Integer .MAX_VALUE;
        for (int num:prices) {
            if(num < min){
                min = num;
            }else {
            max = Math.max(max,num - min);
            }
        }
        return max;
    }
    @Test
    public void p(){
        findKthBit(4,11);
    }
    public char findKthBit(int n, int k) {
        StringBuilder s = new StringBuilder("0");
        int index = s.length();
        while (index < k){//开始进行翻转:
            StringBuilder x = new StringBuilder();
            for (int i = 0; i < s.length(); i++) {
                Character c = s.charAt(i);
                x.append(c.equals('1') ? "0":"1");
            }
            index  = index*2+1;
            s.append("1").append(x.reverse().toString());
        }
        return s.charAt(k);
    }


    public int candy(int[] ratings) {
        int[] left = new int[ratings.length];
        int[] right = new int[ratings.length];
        Arrays.fill(left, 1);
        Arrays.fill(right, 1);
        for(int i = 1; i < ratings.length; i++) {
            if(ratings[i] > ratings[i - 1]) {
                left[i] = left[i - 1] + 1;
            }
        }
        int count = left[ratings.length - 1];
        for(int i = ratings.length - 2; i >= 0; i--) {
            if(ratings[i] > ratings[i + 1]) {
                right[i] = right[i + 1] + 1;
            }
            count += Math.max(left[i], right[i]);
        }
        return count;
    }
    public static boolean isaccept(String x){
        Character c = x.charAt(0);
        if(!Character.isLetter(c)){
            return  false;
        }
        int cc = 0;int index = 0;
        for (char xx:x.toCharArray()) {
            if(Character.isDigit(xx)){
                cc++;
            }else if (Character.isLetter(xx)){
                index ++;
            }else {
                return false;
            }
        }
        return  cc > 0 && index >0;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 次数，行数
        int times = scanner.nextInt();
        List<String> list = new ArrayList<>();
        for (int i = 0; i < times; i++) {
            // 每一行
            list.add(scanner.next());
        }
        for (String eachTry : list) {
            boolean df =isaccept(eachTry);
            if(df){
                System.out.println("Accept");
            }else {
                System.out.println("Wrong");
            }
        }
    }




}
